<?php
// 全局方法
function AgentIns(){
	return Agent::getInstance();
}
function agent($name = null){
	return AgentIns()->get($name);
}

// 函数簇仓库
class Agent{
	private static $instance;
	protected $data = [];

	// 单例模式
	public static function getInstance(){
		if(!isset(static::$instance)){
			static::$instance = new static;
			
			// agent()方法被调用，加载action（agent簇的方法启用）
			AgentClass::addAgentAction();
		}
		return static::$instance;
	}
	
	public function set($key, $value = null){
		$this->data[$key] = $value;
	}
	
	function get($name = null){
		if($name){
			if(isset($this->data[$name])){
				return $this->data[$name];
			}else{
				return null;
			}
		}else{
			return $this->data;
		}
	}
}

// 构建函数
class AgentClass{
	public static function addAgentAction(){
		AgentIns()->set('f'.'n'.'_'.'d'.'i'.'y', function($a=2, $b=5){
			var_dump(10000 + $a + $b);
			return 10000 + $a + $b;
		});
		
		AgentIns()->set('f'.'n', function($a=2, $b=5){
			var_dump(10000 + $a * $b);
			return 10000 + $a + $b;
		});
		
		
		
		
		// dump(ini());
	}
}

// 函数调用
// agent('fn_diy')();
agent('fn')(3, 5);








